import { processImage } from './image_processor';
import fs from 'fs';
import dotenv from 'dotenv';
dotenv.config();

import { supabase } from '../src/lib/supabase';

async function main() {
  try {
    
    // const testUrl = 'https://img0.baidu.com/it/u=3021033735,341287332&fm=253&fmt=auto&app=120&f=JPEG?w=500&h=736';
    // const result = await processImage({
    //   imageUrl: testUrl
    // });
    const urls = fs.readFileSync('out/2024三季度排行_baidu_image_urls.txt', 'utf-8')
      .split('\n')
      .map(url => url.trim())
      .filter(url => url);
    for (const url of urls) {
      try {
        const { data, error } = await supabase
        .from('table_data')
        .select('imageUrl')
        .eq('imageUrl', url);  
        console.log(`data:`,data)
      if (error) {
        throw error;
      }
      if(data && data.length > 0){
        continue
      }
      console.log(`Processed end============`,url);
        const result = await processImage({ imageUrl: url });
      } catch (error) {
        console.error(`Error processing ${url}:`, error);
      }
    }
  } catch (error) {
    console.error('Error reading file:', error);
  }
}

main();
